import { Alert } from "../../../com/mui/controls/Alert";
import { ErrorCode } from "../../common/error/ErrorCode";
import { GameController } from "../mvc/GameController";
import { Exception } from "../../../Framework/Util/Exception";
import { SErrorMsg } from "../../../Message/Public/SErrorMsg";
import { SecTimer } from "../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../com/gengine/core/frame/TimerType";
import { Global } from "../../../com/gengine/global/Global";
import { EShowArea } from "../../../Message/Public/EShowArea";
import { ChatType } from "../view/chat/chatViewData/ChatType";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { DataEvent } from "../events/DataEvent";
import { EventName } from "../mvc/EventName";
import { MsgBroadCastImpl } from "./MsgBroadCastImpl";
import { MsgTipTextImpl } from "./MsgTipTextImpl";
import { MsgSpeakerImpl } from "./MsgSpeakerImpl";
import { MsgFloatWordImpl } from "./MsgFloatWordImpl";
import { MsgTaskShowImpl } from "./MsgTaskShowImpl";
import { MsgCopyTaskEndImpl } from "./MsgCopyTaskEndImpl";
import { MsgIssmNoticeItemPanel } from "./MsgIssmNoticeItemPanel";
import { MsgRollRadioImpl } from "./MsgRollRadioImpl";
import { MsgRollTipsImpl } from "./MsgRollTipsImpl";
import { MsgGuideTipsImpl } from "./MsgGuideTipsImpl";
import { MsgSceneInfoImpl } from "./MsgSceneInfoImpl";
import { MsgPlotShowImpl } from "./MsgPlotShowImpl";
import { ILayer } from "../../mvc/interfaces/ILayer";
import { MsgTypeImpl } from "./MsgTypeImpl";
import { MsgType } from "./MsgType";
import { PlayerMiniInfo } from "../model/PlayerMiniInfo";
import { ErrorCodeConfig } from "../resource/ErrorCodeConfig";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { Log } from "../../../com/gengine/debug/Log";
import { DefaultMsg } from "../../../MsgType/DefaultMsg";
type int = number;
//class MsgManager
    
    export  class MsgManager
    {
        

        public static hidePlotMsg(): void
        {
            MsgManager._msgPlotInfo.hideMsg();
            return;
        }

        public static alertError(arg1: int): void
        {
            Alert.show("错误码：" + arg1 + "  信息：" + ErrorCode.getErrorStringByCode(arg1), "错误信息");
            return;
        }

        public static alertIssm(arg1: string): void
        {
            return;
        }

        public static addChatMsg(arg1: Object, arg2: string): void
        {
            GameController.chat.addTipMsg(arg1, arg2);
            return;
        }

        public static systemError(arg1: Object): void
        {
            var loc1=0;
            var loc4=null;
            var loc5=null;
            var loc2="";
            var loc3="";
            if (typeof arg1 === "exception") 
            {
                loc1 = (loc4 = arg1 as Exception).code;
                loc2 = loc4.message;
                loc3 = "RMI系统错误:" + loc4.method + "，code：" + loc4.code;
                MsgManager.rmiCallback(loc4);
            }
            else if (typeof arg1 === "serrormsg") 
            {
                loc1 = (loc5 = arg1 as SErrorMsg).code;
                loc2 = loc5.message;
                loc3 = "cmd错误:,code：" + arg1.code;
                MsgManager.errorCallback(loc5);
            }
            MsgManager.showErrorByCode(loc1, loc3, loc2);
            return;
        }

        public static showTaskTarget(arg1: string, arg2: int=5): void
        {
            if (!arg1) 
            {
                return;
            }
            MsgManager._msgTaskShowImpl.showTarget(arg1, arg2);
            return;
        }

        /* internal  */static sendErrorMsgCount(arg1: string, arg2: int): void
        {
            var value: string;
            var num: int;
            var timer: SecTimer;
            var onEnterFrameHandler: Function;

            var loc1;
            onEnterFrameHandler = null;
            value = arg1;
            num = arg2;
            onEnterFrameHandler = (arg1: SecTimer): void
            {
                MsgManager.addBroadCast(value);
                return;
            }
            timer = new SecTimer(1, num);
            timer.addListener(TimerType.ENTERFRAME, onEnterFrameHandler);
            timer.start();
            return;
        }

        /* internal  */static addTips(arg1: string, arg2: string, arg3: int): void
        {
            if (Global.isDebugModle) 
            {
                arg1 = arg1 + "，错误信息：" + arg2;
            }
            else 
            {
                if (arg3 == 0) 
                {
                    return;
                }
                arg1 = arg2;
            }
            if (arg3 & EShowArea._EShowAreaChat) 
            {
                MsgManager.addChatMsg(arg1, ChatType.Tips);
            }
            if (arg3 & EShowArea._EShowAreaHistory) 
            {
                MsgManager.addTipText(arg1);
            }
            if (arg3 & EShowArea._EShowAreaMiddle) 
            {
                MsgManager.addBroadCast(arg1);
            }
            if (arg3 & EShowArea._EShowAreaRightDown) 
            {
                MsgManager.showRollTipsMsg(arg1);
            }
            return;
        }

        /* internal  */static errorCallback(arg1: SErrorMsg): void
        {
            var loc1=arg1.code;
            switch (loc1) 
            {
                case ErrorCode.ErrorPublic_CopyGroupNotExsit:
                {
                    NetDispatcher.dispatchCmd(ServerCommand.Copy_GroupNoExist, null);
                    break;
                }
                case ErrorCode.ErrorPublic_CannotGetPetCpnReward:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetCpnOpenWindow));
                    break;
                }
            }
            return;
        }

        /* internal  */static rmiCallback(arg1: Exception): void
        {
            var loc1=arg1.code;
            switch (loc1) 
            {
                case ErrorCode.ErrorGate_TransportHadTask:
                {
                    break;
                }
            }
            return;
        }

        public static get rollMsgLength(): int
        {
            return MsgManager._msgRollTipsImpl.msgLength;
        }

        
        {
            MsgManager._msgBroadImpl = new MsgBroadCastImpl();
            MsgManager._msgTipImpl = new MsgTipTextImpl();
            MsgManager._msgSpeakerImpl = new MsgSpeakerImpl();
            MsgManager._msgFloatWordImpl = new MsgFloatWordImpl();
            MsgManager._msgTaskShowImpl = new MsgTaskShowImpl();
            MsgManager._msgCopyTaskEndImpl = new MsgCopyTaskEndImpl();
            MsgManager._msgIssmImpl = new MsgIssmNoticeItemPanel();
            MsgManager._msgRollRadioImpl = new MsgRollRadioImpl();
            MsgManager._msgRollTipsImpl = new MsgRollTipsImpl();
            MsgManager._msgGuideTipsImpl = new MsgGuideTipsImpl();
            MsgManager._msgSceneInfo = new MsgSceneInfoImpl();
            MsgManager._msgPlotInfo = new MsgPlotShowImpl();
        }

        public static addIssmNoticeItemPanelStage(arg1: Object /* flash.display.DisplayObjectContainer */): void
        {
            arg1.addChild(MsgManager._msgIssmImpl);
            return;
        }

        public static addBroadStage(arg1: ILayer): void
        {
            MsgManager._msgBroadImpl.layer = arg1;
            return;
        }

        public static addTipStage(arg1: Object /* flash.display.DisplayObjectContainer */): void
        {
            arg1.addChild(MsgManager._msgTipImpl);
            return;
        }

        public static addSpeakerStage(arg1: Object /* flash.display.DisplayObjectContainer */): void
        {
            arg1.addChild(MsgManager._msgSpeakerImpl);
            return;
        }

        public static resize(): void
        {
            MsgManager._msgBroadImpl.stageResize();
            MsgManager._msgTipImpl.stageResize();
            MsgManager._msgSpeakerImpl.setPxy();
            MsgManager._msgFloatWordImpl.stageResize();
            MsgManager._msgTaskShowImpl.stageResize();
            MsgManager._msgCopyTaskEndImpl.stageResize();
            MsgManager._msgRollRadioImpl.stageResize();
            MsgManager._msgRollTipsImpl.stageResize();
            MsgManager._msgSceneInfo.stageReseze();
            MsgManager._msgPlotInfo.stageReseze();
            return;
        }

        public static chatResize(): void
        {
            MsgManager._msgSpeakerImpl.setPxy();
            return;
        }

        public static addBroadCast(arg1: Object, arg2: MsgTypeImpl=null): void
        {
            if (arg1 == null) 
            {
                return;
            }
            arg2 = arg2 != null ? arg2 : DefaultMsg;
            MsgManager._msgBroadImpl.showNotice(arg1.toString());
            return;
        }

        public static addTipText(arg1: Object, arg2: MsgTypeImpl=null): void
        {
            if (arg1 == null) 
            {
                return;
            }
            arg2 = arg2 != null ? arg2 : DefaultMsg;
            MsgManager._msgTipImpl.showInfo(arg1.toString(), arg2.color, arg2.delay);
            GameController.sysHistory.addHistroy(arg1, arg2);
            return;
        }

        public static addSpeakerText(arg1: PlayerMiniInfo, arg2: string, arg3: MsgTypeImpl=null): void
        {
            if (arg1 == null) 
            {
                return;
            }
            arg3 = arg3 != null ? arg3 : DefaultMsg;
            MsgManager._msgSpeakerImpl.showSpeakerNotice(arg1, arg2, arg3);
            return;
        }

        public static addFloatWord(arg1: Object, arg2: MsgTypeImpl=null): void
        {
            if (arg1 == null) 
            {
                return;
            }
            arg2 = arg2 != null ? arg2 : DefaultMsg;
            MsgManager._msgFloatWordImpl.showWord(arg1.toString());
            return;
        }

        public static removeFloatWord(): void
        {
            MsgManager._msgFloatWordImpl.dispose();
            return;
        }

        public static showErrorByCode(arg1: int, arg2: string="", arg3: string=""): void
        {
            var loc1;
            if (loc1 = ErrorCodeConfig.instance.getInfoByCode(arg1)) 
            {
                if (loc1.showServerMsg != 1) 
                {
                    MsgManager.addTips(arg2, loc1.errorStr, loc1.display);
                }
                else 
                {
                    MsgManager.addTips(arg2, arg3, loc1.display);
                }
                if (arg1 == ErrorCode.ErrorCell_EscortIsAttacked) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.EscortIsAttacked));
                    MsgManager.sendErrorMsgCount(loc1.errorStr, 20);
                }
            }
            else 
            {
                MsgManager.addTips(arg2, ErrorCode.getErrorStringByCode(arg1), 0);
            }
            if (arg1 != ErrorCode.ErrorCell_ObstructNotFight) 
            {
                if (arg1 != ErrorCode.ErrorCell_CollectHasOwner) 
                {
                    if (arg1 != ErrorCode.ErrorCell_FightToEntityNotOnline) 
                    {
                        if (arg1 != ErrorCode.ErroeCell_CollectToEntityNotOnline) 
                        {
                            if (arg1 == ErrorCode.ErrorCell_FightTooFar || arg1 == ErrorCode.ErrorCell_SkillTooFar) 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.FightTargetIsTooFar));
                            }
                            else if (arg1 != ErrorCode.ErrorCell_CollectDistanceTooFar) 
                            {
                                if (arg1 != ErrorCode.ErrorCell_InputPointError) 
                                {
                                    if (arg1 == ErrorCode.ErrorGate_BagBagIsFull || arg1 == ErrorCode.ErrorGate_BagSlotNotEnough) 
                                    {
                                        NetDispatcher.dispatchCmd(ServerCommand.BackPackFullCommand, null);
                                    }
                                }
                                else 
                                {
                                    Dispatcher.dispatchEvent(new DataEvent(EventName.InputPointError));
                                }
                            }
                            else 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.CollectTargetIsTooFar));
                            }
                        }
                        else 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.ColloectTargetNotOnLine));
                        }
                    }
                    else 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.FightEntityNotOnLine));
                    }
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CollectHasOwner));
                }
            }
            else 
            {
                RolePlayer.instance.obstructNotFight();
            }
            return;
        }

        public static removeTaskTarget(): void
        {
            MsgManager._msgTaskShowImpl.hide();
            return;
        }

        public static showRollRadioMsg(arg1: string, arg2: int=3, arg3: int=2): void
        {
            if (arg1 == null || arg1 == "") 
            {
                return;
            }
            MsgManager._msgRollRadioImpl.showMsg(arg1, arg2, arg3);
            return;
        }

        public static hideRollRadioMsg(): void
        {
            MsgManager._msgRollRadioImpl.hide();
            return;
        }

        public static showRollTipsMsg(arg1: string): void
        {
            if (arg1 == null || arg1 == "") 
            {
                return;
            }
            MsgManager._msgRollTipsImpl.showMsg(arg1);
            Log.debug(arg1);
            return;
        }

        public static showGuideTips(arg1: string, arg2: int, arg3: int, arg4: Object /* flash.display.DisplayObjectContainer */=null, arg5: int=0): void
        {
            MsgManager._msgGuideTipsImpl.show(arg1, arg2, arg3, arg4, arg5);
            return;
        }

        public static hideGuideTips(): void
        {
            MsgManager._msgGuideTipsImpl.hide();
            return;
        }

        public static showCopyEndStr(arg1: string, arg2: int, arg3: int, arg4: Function=null): void
        {
            MsgManager._msgCopyTaskEndImpl.show(arg1, arg2, arg3, arg4);
            return;
        }

        public static hideCopyEndStr(): void
        {
            MsgManager._msgCopyTaskEndImpl.hide();
            return;
        }

        public static showSceneDes(arg1: string, arg2: Array<any>): void
        {
            if (arg1 && arg2 && !(arg1 == "") && arg2.length > 0) 
            {
                MsgManager._msgSceneInfo.showMsg(arg1, arg2);
            }
            return;
        }

        public static hideSceneDes(): void
        {
            MsgManager._msgSceneInfo.hideMsg();
            return;
        }

        public static showPlotMsg(arg1: string, arg2: Function=null): void
        {
            MsgManager._msgPlotInfo.showMsg(arg1, arg2);
            return;
        }

        /* internal */ static /* var */_msgBroadImpl: MsgBroadCastImpl;

        /* internal */ static /* var */_msgTipImpl: MsgTipTextImpl;

        /* internal */ static /* var */_msgSpeakerImpl: MsgSpeakerImpl;

        /* internal */ static /* var */_msgFloatWordImpl: MsgFloatWordImpl;

        /* internal */ static /* var */_msgTaskShowImpl: MsgTaskShowImpl;

        public static /* var */_msgIssmImpl: MsgIssmNoticeItemPanel;

        /* internal */ static /* var */_msgRollRadioImpl: MsgRollRadioImpl;

        /* internal */ static /* var */_msgRollTipsImpl: MsgRollTipsImpl;

        /* internal */ static /* var */_msgGuideTipsImpl: MsgGuideTipsImpl;

        /* internal */ static /* var */_msgSceneInfo: MsgSceneInfoImpl;

        /* internal */ static /* var */_msgPlotInfo: MsgPlotShowImpl;

        /* internal */ static /* var */_msgCopyTaskEndImpl: MsgCopyTaskEndImpl;
    }
